﻿namespace OleDbDAL.Processing
{
    using DBUtility;
    using IDal.Processing;
    using Model.Processing;
    using System;
    using System.Data;
    using System.Text;

    public class TeaMixedApp : ITeaMixed
    {
        private string dbname = "Systems";

        public void Add(TeaMixedEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_TeaMixed(");
            builder.Append("ChainNum,MixedNum,TeaType,LotNum,NewTeaDlid,NewTeaWeight,CommId,CommName,CommUnit,CommPrice,CreateMan,CreateTime,IsCheck,CheckMan,CheckTime,Remark");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.ChainNum + ",");
            builder.Append("'" + model.MixedNum + "',");
            builder.Append("" + model.TeaType + ",");
            builder.Append("'" + model.LotNum + "',");
            builder.Append("" + model.NewTeaDlid + ",");
            builder.Append("" + model.NewTeaWeight + ",");
            builder.Append("" + model.CommId + ",");
            builder.Append("'" + model.CommName + "',");
            builder.Append("" + model.CommUnit + ",");
            builder.Append("" + model.CommPrice + ",");
            builder.Append("" + model.CreateMan + ",");
            builder.Append("'" + model.CreateTime + "',");
            builder.Append("" + model.IsCheck + ",");
            builder.Append("" + model.CheckMan + ",");
            builder.Append("'" + model.CheckTime + "',");
            builder.Append("'" + model.Remark + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Check(TeaMixedEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_TeaMixed set ");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("IsCheck=" + model.IsCheck);
            builder.Append(" where Mixed=" + model.Mixed + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int Mixed)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_TeaMixed ");
            builder.Append(" where Mixed=" + Mixed);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_TeaMixed ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by Mixed ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "Mixed", "T_TeaMixed", swhere);
        }

        public TeaMixedEnt GetModel(int Mixed)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select Mixed,ChainNum,MixedNum,TeaType,LotNum,NewTeaDlid,NewTeaWeight,CommId,CommName,CommUnit,CommPrice,CreateMan,CreateTime,IsCheck,CheckMan,CheckTime,Remark from T_TeaMixed ");
            builder.Append(" where Mixed=" + Mixed);
            TeaMixedEnt ent = new TeaMixedEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.Mixed = Mixed;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["ChainNum"].ToString() != "")
                {
                    ent.ChainNum = int.Parse(table.Rows[0]["ChainNum"].ToString());
                }
                ent.MixedNum = table.Rows[0]["MixedNum"].ToString();
                if (table.Rows[0]["TeaType"].ToString() != "")
                {
                    ent.TeaType = int.Parse(table.Rows[0]["TeaType"].ToString());
                }
                ent.LotNum = table.Rows[0]["LotNum"].ToString();
                if (table.Rows[0]["NewTeaDlid"].ToString() != "")
                {
                    ent.NewTeaDlid = int.Parse(table.Rows[0]["NewTeaDlid"].ToString());
                }
                if (table.Rows[0]["NewTeaWeight"].ToString() != "")
                {
                    ent.NewTeaWeight = decimal.Parse(table.Rows[0]["NewTeaWeight"].ToString());
                }
                if (table.Rows[0]["CommId"].ToString() != "")
                {
                    ent.CommId = int.Parse(table.Rows[0]["CommId"].ToString());
                }
                ent.CommName = table.Rows[0]["CommName"].ToString();
                if (table.Rows[0]["CommUnit"].ToString() != "")
                {
                    ent.CommUnit = int.Parse(table.Rows[0]["CommUnit"].ToString());
                }
                if (table.Rows[0]["CommPrice"].ToString() != "")
                {
                    ent.CommPrice = decimal.Parse(table.Rows[0]["CommPrice"].ToString());
                }
                if (table.Rows[0]["CreateMan"].ToString() != "")
                {
                    ent.CreateMan = int.Parse(table.Rows[0]["CreateMan"].ToString());
                }
                if (table.Rows[0]["CreateTime"].ToString() != "")
                {
                    ent.CreateTime = DateTime.Parse(table.Rows[0]["CreateTime"].ToString());
                }
                if (table.Rows[0]["IsCheck"].ToString() != "")
                {
                    ent.IsCheck = int.Parse(table.Rows[0]["IsCheck"].ToString());
                }
                if (table.Rows[0]["CheckMan"].ToString() != "")
                {
                    ent.CheckMan = int.Parse(table.Rows[0]["CheckMan"].ToString());
                }
                if (table.Rows[0]["CheckTime"].ToString() != "")
                {
                    ent.CheckTime = DateTime.Parse(table.Rows[0]["CheckTime"].ToString());
                }
                ent.Remark = table.Rows[0]["Remark"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_TeaMixed ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "Mixed");
        }

        public void Update(TeaMixedEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_TeaMixed set ");
            builder.Append("ChainNum=" + model.ChainNum + ",");
            builder.Append("MixedNum='" + model.MixedNum + "',");
            builder.Append("TeaType=" + model.TeaType + ",");
            builder.Append("LotNum='" + model.LotNum + "',");
            builder.Append("NewTeaDlid=" + model.NewTeaDlid + ",");
            builder.Append("NewTeaWeight=" + model.NewTeaWeight + ",");
            builder.Append("CommId=" + model.CommId + ",");
            builder.Append("CommName='" + model.CommName + "',");
            builder.Append("CommUnit=" + model.CommUnit + ",");
            builder.Append("CommPrice=" + model.CommPrice + ",");
            builder.Append("CreateMan=" + model.CreateMan + ",");
            builder.Append("CreateTime='" + model.CreateTime + "',");
            builder.Append("IsCheck=" + model.IsCheck + ",");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("Remark='" + model.Remark + "'");
            builder.Append(" where Mixed=" + model.Mixed + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

